package com.agriculture.data_demo.controller.api;

import com.agriculture.data_demo.controller.BaseController;
import com.agriculture.data_demo.dto.PageResult;
import com.agriculture.data_demo.dto.Result;
import com.agriculture.data_demo.service.HenService;
import com.agriculture.data_demo.vo.sys.HenBatchVo;
import com.agriculture.data_demo.vo.sys.HenDailyVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author morningbear
 * @date 20.10.15
 */
@ApiModel(value = "蛋鸡数据Controller")
@Slf4j
@RestController
public class HenController extends BaseController {

    @Resource
    private HenService henService;

    @ApiOperation(value = "查询所有蛋鸡批次数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping(value = "/hen_batch")
    public ResponseEntity<HenBatchVo> getAllHenBatch(@RequestParam(value = "pageNumber",
    defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15")
    Integer pageSize){
        return new ResponseEntity(new Result<PageResult<HenBatchVo>>().ok("success",
                henService.getAllHenBatch(pageNumber, pageSize)), HttpStatus.OK);
    }

    @ApiOperation(value = "查询所有蛋鸡生产周期数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping(value = "/hen_daily")
    public ResponseEntity<HenDailyVo> getAllHenDaily(@RequestParam(value = "pageNumber",
            defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15")
            Integer pageSize){
        return new ResponseEntity(new Result<PageResult<HenDailyVo>>().ok("success",
                henService.getAllHenDaily(pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     *
     * @param startDate 开始日期
     * @param endDate 截至日期
     * @param pageNumber 页数
     * @param pageSize 页大小
     * @return 某个时间段的蛋鸡生产周期数据
     */
    @ApiOperation(value = "查询某个时间段的蛋鸡生产周期数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始日期"),
            @ApiImplicitParam(name = "endDate", value = "截至日期"),
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping(value = "/getHenDailyByDate")
    public ResponseEntity<HenDailyVo> getHenDailyByDate(@RequestParam(value = "startDate", defaultValue = "2020-10-01")@JsonFormat
            (timezone = "GMT+8",pattern = "yyyy-MM-dd")Date startDate, @RequestParam(value = "endDate", defaultValue = "2020-10-31")@JsonFormat
            (timezone = "GMT+8",pattern = "yyyy-MM-dd")Date endDate, @RequestParam(value = "pageNumber", defaultValue = "0")
            Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize){
        return new ResponseEntity(new Result<PageResult<HenDailyVo>>().ok("success",
                henService.getHenDailyByDate(startDate, endDate, pageNumber, pageSize)), HttpStatus.OK);
    }

    /**
     *
     * @param startDate 开始日期
     * @param endDate 截至日期
     * @param pageNumber 页数
     * @param pageSize 页大小
     * @return 某个时间段的蛋鸡生产批次数据
     */
    @ApiOperation(value = "查询某个时间段的蛋鸡生产批次数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始日期"),
            @ApiImplicitParam(name = "endDate", value = "截至日期"),
            @ApiImplicitParam(name = "pageNumber", value = "页码"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    @GetMapping(value = "/getHenBatchByDate")
    public ResponseEntity<HenBatchVo> getHenBatchByDate(@RequestParam(value = "startDate", defaultValue = "2020-10-01")@JsonFormat
            (timezone = "GMT+8",pattern = "yyyy-MM-dd")Date startDate, @RequestParam(value = "endDate", defaultValue = "2020-10-31")@JsonFormat
            (timezone = "GMT+8",pattern = "yyyy-MM-dd")Date endDate, @RequestParam(value = "pageNumber", defaultValue = "0")
            Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "15") Integer pageSize){
        return new ResponseEntity(new Result<PageResult<HenBatchVo>>().ok("success",
                henService.getHenBatchByDate(startDate, endDate, pageNumber, pageSize)), HttpStatus.OK);
    }
}
